'use strict'


var OSS = require('ali-oss');
var STS = OSS.STS;
var co = require('co');

var sts = new STS({
    accessKeyId: 'LTAITldlbkDhCEVv',
    accessKeySecret: 'x7hE3GZFzmJkvkjdbWu9lkp78hoq6A',
});
var rolearn = 'acs:ram::ID:role/ram';

var policy = {
    "Version": "1",
    "Statement": [
    {
        "Effect": "Allow",
        "Action": [
        "oss:GetObject",
        "oss:PutObject"
        ],
        "Resource": [
        "acs:oss:*:*:Bucket",
        "acs:oss:*:*:BucketName/*"
        ]
    }
    ]
};

class OssUploadService {

    getOssToken(req, res){
        var result = co(function* async () {
            console.log('caonima');
            var token = yield sts.assumeRole(rolearn, policy, 15 * 60, 'ossupload');
            console.log(token);
            res.json({
                token:token.credentials
            })
        }).catch(function (err) {
        });
    }
}

module.exports = new OssUploadService()